package com.boilermaker.mybatislearning.dao;

import com.boilermaker.mybatislearning.model.UserInfo;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserInfoMapper {

//    @Results(id = "BaseMap", value = {
//            @Result(column = "delete_flag", property = "deleteFlag"),
//            @Result(column = "create_time", property = "createTime"),
//            @Result(column = "update_time", property = "updateTime")
//    })
    @Select("select * from user_info")
    List<UserInfo> selectAll();

    //@ResultMap("BaseMap")
    @Select("select * from user_info where id = #{id}")
    UserInfo selectAllById(Integer id);

    //@ResultMap("BaseMap")
    // 使用自增主键
    @Options(useGeneratedKeys = true, keyProperty = "id")
    @Insert("insert into user_info (username, password, age) " +
            "values (#{username}, #{password}, #{age})")
    // 返回改变的行数
    Integer insertUser(UserInfo userInfo);

    @Delete("delete from user_info where id = #{id}")
    Integer deleteUser(Integer id);

    @Update("update user_info set username = #{username}, password = #{password} " +
            "where id = #{id}")
    Integer updateUser(UserInfo userInfo);

}
